﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Joyintech.Model.inpiao365;
using Joyintech.BLL.inpiao365;
using System.Data;


namespace Joyintech.Web.inpiao365.PhenixTicket
{
    public partial class phenix_PayCenter : System.Web.UI.Page
    {
        #region 页面绑定字段

        protected string movieimg;//电影片照
        protected string orderid;//订单ID
        protected string moviename;//电影名称
        protected string moviecount;//订单票数
        protected string movietype;//电影类型
        protected string MovieSeatTime;//放映时间
        protected string TheaterName;//影院名称
        protected string TheaterRoomName;//影厅名称
        protected string mobile;//订单手机号码
        protected string orderTime;//订单时间
        protected string CustomerAccount;//账户余额
        protected string price;//单价
        protected string MovieSeatId;//座位
        protected string paytotal;//应付款
        protected string month;//月
        protected string day;//天
        protected string minutes;//分
        protected string seconds;//秒
        protected string time;//时间
        protected string xingqi;//星期几

        #endregion



        private void Page_Load(object sender, EventArgs e)
        {
            customer currentCustomer = customer_BLL.GetInstance().GetCurrentCustomer();
            if (currentCustomer == null)
            {
                Response.Redirect("/UserCenter/UserLogin.aspx");
            }
            if (!this.IsPostBack)
            {
                string orderid = Request["id"];
                if (!string.IsNullOrEmpty(orderid))
                {
                    Bind(int.Parse(orderid));
                }
            }
        }



        /// <summary>
        /// 提交订单付款事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            order_BLL bll = new order_BLL();
            customer currentCustomer = customer_BLL.GetInstance().GetCurrentCustomer();
            string orderid = Request["id"];
            order order = bll.GetModel(int.Parse(orderid));
            order.RecMobile = RecMobile.Text;
            order.PayTime = DateTime.Now;//支付时间
            order.TotalMoney = 0;//支付金额
            order.OrderState = true;//付款状态
            order.OrderVerifyCode = "1111";//验证码
            if (bll.Update(order) > 0)
            {
                Response.Redirect("/UserCenter/MyTicket_order.aspx");
            }
        }

        /// <summary>
        /// 页面绑定字段赋值
        /// </summary>
        protected void Bind(int id)
        {
            order_BLL bll = new order_BLL();
            DataSet ds = bll.GetFullModel(id);
            DataRow dr = ds.Tables[0].Rows[0];
            movieimg = dr["MovieLogo"].ToString();//电影片照
            orderid = id.ToString();//订单ID
            moviename = dr["MovieName"].ToString();//电影名称
            MovieSeatId = dr["MovieSeatId"].ToString();
            moviecount = MovieSeatId.Split(',').Length.ToString();//订单票数
            movietype = dr["MovieType"].ToString();//电影类型
            MovieSeatTime = dr["MovieSeatTime"].ToString();//放映时间
            TheaterName = dr["TheaterName"].ToString();//影院名称
            TheaterRoomName = dr["TheaterRoomName"].ToString();//影厅名称
            RecMobile.Text = dr["RecMobile"].ToString();//订单手机号码
            
            orderTime = dr["OrderTime"].ToString();//订单时间

            DateTime dt = DateTime.Parse(orderTime);
            month = dt.Month.ToString();
            day = dt.Day.ToString();
            xingqi = TransformDay((int)(dt.DayOfWeek));
            time = dt.TimeOfDay.ToString();
            otime.Value = orderTime;


            CustomerAccount = customer_BLL.GetInstance().GetCurrentCustomer().CustomerAccount.HasValue ? customer_BLL.GetInstance().GetCurrentCustomer().CustomerAccount.ToString() : "0.00";//账户余额
            price = dr["Price"].ToString();
            paytotal = (double.Parse(price) * int.Parse(moviecount)).ToString();

            if (double.Parse(CustomerAccount) < double.Parse(paytotal))
            {
                jinggao.Text = "!账户余额不足，请充值后付款";

            }
        }

        /// <summary>
        /// 转换成中文星期
        /// </summary>
        /// <param name="week"></param>
        /// <returns></returns>
        private string TransformDay(int week)
        {
            string xingqi = string.Empty;
            if (week == 0)
            {
                xingqi = "星期日";
            }
            else if (week == 1)
            {
                xingqi = "星期一";
            }
            else if (week == 2)
            {
                xingqi = "星期二";
            }
            else if (week == 3)
            {
                xingqi = "星期三";
            }
            else if (week == 4)
            {
                xingqi = "星期四";
            }
            else if (week == 5)
            {
                xingqi = "星期五";
            }
            else
            {
                xingqi = "星期六";
            }

            return xingqi;
        }
    }
}